    package com.ruoyi.web.controller.project;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.domain.entity.ProjectCosting;
import com.ruoyi.project.domain.entity.ProjectPay;
import com.ruoyi.project.domain.query.ProjectCostingQuery;
import com.ruoyi.project.domain.query.ProjectPayQuery;
import com.ruoyi.project.service.IProjectCostingService;
import com.ruoyi.project.service.IProjectPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

    @RestController
    @RequestMapping("/project/costing")
    @Api(tags = "附件信息", description = "附件信息")
    public class ProjectCostingController {


        @Resource
        private IProjectCostingService projectCostingService;

        @GetMapping(value = "/list")
        public R getList(ProjectCostingQuery query) {
            return R.ok(projectCostingService.getList(query));
        }

        @ApiOperation("分页")
        @GetMapping(value = "/page")
        public R<TableDataInfo> page(ProjectCostingQuery query) {
            return R.ok(projectCostingService.page(query));
        }


        @ApiOperation("新增")
        @PostMapping(value = "/save")
        public R add(@RequestBody ProjectCosting project) {
            return R.ok(projectCostingService.addInfo(project));
        }


        @ApiOperation("修改")
        @PutMapping
        public R update(@RequestBody ProjectCosting project) {
            return R.ok(projectCostingService.updateInfo(project));
        }


        @ApiOperation("删除")
        @DeleteMapping (value = "/{id}")
        public R delete(  @PathVariable("id") String id) {
            return R.ok(projectCostingService.deleteInfo(id));
        }



        @ApiOperation("详情")
        @GetMapping(value = "/{id}")
        public R<ProjectCosting> getDetails(@PathVariable  String id) {
            return R.ok(projectCostingService.getById(id));
        }



        @PostMapping("/importData")
        public AjaxResult importData(MultipartFile file) throws Exception
        {
            ExcelUtil<ProjectCosting> util = new ExcelUtil<ProjectCosting>(ProjectCosting.class);
            List<ProjectCosting> list = util.importExcel(file.getInputStream());
            String message = projectCostingService.importCosting(list,"",false,"");
            return AjaxResult.success(message);
        }

        @GetMapping("/importTemplate")
        public AjaxResult importTemplate()
        {
            ExcelUtil<ProjectCosting> util = new ExcelUtil<ProjectCosting>(ProjectCosting.class);
            return util.importTemplateExcel("用户数据");
        }

    }
